package cn.ronghuanet.base.service.impl;

import cn.ronghuanet.base.mapper.BaseMapper;
import cn.ronghuanet.base.query.BaseQuery;
import cn.ronghuanet.base.service.IBaseService;
import cn.ronghuanet.base.util.PageInfo;
import cn.ronghuanet.org.domain.Department;
import cn.ronghuanet.org.mapper.DepartmentMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.io.Serializable;
import java.util.List;
import java.util.Objects;

public class BaseServiceImpl<T> implements IBaseService<T> {
    @Autowired
    private BaseMapper<T> mapper;

    @Transactional
    @Override
    public void insert(T department) {
        mapper.insert(department);


    }
    @Transactional
    @Override
    public void update(T department) {

        mapper.update(department);
    }


    @Transactional
    @Override
    public void delete(Serializable id) {
        mapper.delete(id);
    }



    @Override
    public List<T> queryAll() {
        return mapper.queryAll();
    }

    @Override
    public T queryById(Serializable id) {
        return mapper.queryById(id);
    }



    @Override
    public PageInfo<T> queryPage(BaseQuery baseQuery) {
        // 查询总条数
        Long total = mapper.queryTotal(baseQuery);
        // 查询分页数据
        if (total != 0){
            List<T> list = mapper.queryPage(baseQuery);
            return new PageInfo<T>(total,list);
        }
        return new PageInfo<T>();
    }

    @Override
    public void batchDelete(List<Long> ids) {
        mapper.batchDelete(ids);
    }
}
